const path = require('path')
const express = require('express')
const multer = require('multer')
const cors = require('cors')
const tokenjs = require('./common/token.js')
//自定义路由
const users = require('./router/users.js')
const goods = require('./router/goods.js')
const upload = require('./router/upload.js')
const { token } = require('./db/index.js')
//处理内容
const app = express()
const file = multer({dest: 'public/images'})

//中间件
app.use(express.static(path.join(__dirname, 'public')))
app.use(cors())
app.use(file.any())
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(tokenjs)
app.use('/upload', upload)
app.use('/users', users)
app.use('/goods', goods)

app.listen(8848, ()=>{
    console.log('server ok');
})